from fastapi.responses import JSONResponse

from common.base.base_routers import get_custom_router
from services.automatic_control.api import AutomaticControlApi

ac_api = AutomaticControlApi()
ac_router = get_custom_router(ac_api, prefix='/automatic_control', tags=['automatic_control'])


@ac_router.get('/set-loop-state/', response_class=JSONResponse)
async def set_automatic_control_loop_state(state: bool):
    return await ac_api.set_loop_state(state)


@ac_router.get('/get-loop-state/', response_class=JSONResponse)
async def get_automatic_control_loop_state():
    return await ac_api.get_loop_state()


@ac_router.get('/set-adjustment-state/', response_class=JSONResponse)
async def set_adjustment_state(state: bool):
    return await ac_api.set_adjustment_state(state)


@ac_router.get('/get-adjustment-state/', response_class=JSONResponse)
async def get_adjustment_state():
    return await ac_api.get_adjustment_state()


@ac_router.get('/get-actual-reference-freq-40mhz/', response_class=JSONResponse)
async def get_actual_reference_freq_40mhz():
    return await ac_api.get_actual_reference_freq_40mhz()

@ac_router.get('/get-pilot-telemetry/', response_class=JSONResponse)
async def get_pilot_telemetry():
    return await ac_api.get_pilot_telemetry()

@ac_router.get('/carrier-frequency-control/', response_class=JSONResponse)
async def carrier_frequency_control(freq: float):
    return await ac_api.carrier_frequency_control(freq)

@ac_router.get('/get-force-find-pilot/', response_class=JSONResponse)
async def get_force_find_pilot():
    return await ac_api.get_force_find_pilot()

@ac_router.get('/set-force-find-pilot/', response_class=JSONResponse)
async def set_force_find_pilot(state: bool):
    return await ac_api.set_force_find_pilot(state)

